#ifndef MODEL_H
#define MODEL_H

#include <QAbstractTableModel>
#include <QDate>
#include <QUrl>
#include <QXmlQuery>
#include <QDataStream>

class Stream
{
public:
    QUrl url;
    QString mimeType;
    qint64 size; // bytes
    int bitrate; // kbps
    bool isDefault;
};

class Program
{
public:
    ~Program();

public: // stored data
    QString title;
    QString description;
    QUrl link;
    QString guid;
    QDateTime pubDate;
    int duration; // seconds
    QUrl thumbnail;
    QList<Stream*> streams;
    bool seen;
public:
    qint64 diff(const Program& other) const;
public:
    static bool pubDateOrder(const Program* lhs, const Program* rhs);
};

class Channel: public QAbstractTableModel
{
    Q_OBJECT

public:
    ~Channel();

public: // from QAbstractTableModel
    int columnCount(const QModelIndex& parent) const;
    int rowCount(const QModelIndex& parent) const;
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;

public:
    void update(QXmlQuery& query);

public: // stored data
    QString title;
    QString description;
    QUrl link;
    QString guid;
    QList<Program*> programs;
    bool seen;
};

#endif // MODEL_H
